/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nxlv2.nomad.view.ficheClient;

import com.nxlv2.nomad.accessdb.services.CommandeServices;
import com.nxlv2.nomad.accessdb.services.SatisfactionServices;
import com.nxlv2.nomad.businessobjects.Commande;
import com.nxlv2.nomad.businessobjects.Satisfaction;
import com.nxlv2.nomad.businessobjects.TauxSatisfaction;
import com.nxlv2.nomad.view.Welcome;
import javax.swing.JOptionPane;
import org.joda.time.DateTime;

/**
 *
 * @author Nastasia
 */
public class FicheSatisfaction extends javax.swing.JFrame {

    private final Commande commande;
    private final FicheClient ficheClient;
    private final Welcome welcome;

    /**
     * Creates new form FicheSatisfaction
     */
    public FicheSatisfaction(Welcome w, FicheClient fc, Commande com) {
        initComponents();
        this.setLocationRelativeTo(null);
        this.ficheClient = fc;
        this.commande = com;
        this.welcome = w;
        initData();
    }

    public void initData() {
        jLabelTitre.setText("N° " + commande.getNumCommande());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupSatisfaction = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabelTitre = new javax.swing.JLabel();
        jRadioButtonTSatisfait = new javax.swing.JRadioButton();
        jRadioButtonSatisfait = new javax.swing.JRadioButton();
        jRadioButtonPeSatisfait = new javax.swing.JRadioButton();
        jRadioButtonPaSatisfait = new javax.swing.JRadioButton();
        jButtonValider = new javax.swing.JButton();
        jLabelTitre1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Satisfaction");
        setPreferredSize(new java.awt.Dimension(200, 250));

        jPanel1.setPreferredSize(new java.awt.Dimension(199, 200));

        jLabelTitre.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabelTitre.setText("jLabel1");

        buttonGroupSatisfaction.add(jRadioButtonTSatisfait);
        jRadioButtonTSatisfait.setText("Très satisfait");

        buttonGroupSatisfaction.add(jRadioButtonSatisfait);
        jRadioButtonSatisfait.setText("Satisfait");

        buttonGroupSatisfaction.add(jRadioButtonPeSatisfait);
        jRadioButtonPeSatisfait.setText("Peu Satisfait");

        buttonGroupSatisfaction.add(jRadioButtonPaSatisfait);
        jRadioButtonPaSatisfait.setText("Pas satisfait");

        jButtonValider.setText("Valider");
        jButtonValider.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonValiderActionPerformed(evt);
            }
        });

        jLabelTitre1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabelTitre1.setText("Commande");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButtonValider)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jRadioButtonSatisfait)
                                .addComponent(jRadioButtonPaSatisfait)
                                .addComponent(jRadioButtonPeSatisfait)
                                .addComponent(jRadioButtonTSatisfait))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addComponent(jLabelTitre1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabelTitre)))
                .addContainerGap(68, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTitre1)
                .addGap(3, 3, 3)
                .addComponent(jLabelTitre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButtonTSatisfait)
                .addGap(1, 1, 1)
                .addComponent(jRadioButtonSatisfait)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButtonPeSatisfait)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButtonPaSatisfait)
                .addGap(18, 18, 18)
                .addComponent(jButtonValider)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonValiderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonValiderActionPerformed
        boolean buttonPas = jRadioButtonPaSatisfait.isSelected();
        boolean buttonPeu = jRadioButtonPeSatisfait.isSelected();
        boolean buttonSat = jRadioButtonSatisfait.isSelected();
        boolean buttonTre = jRadioButtonTSatisfait.isSelected();

        Satisfaction satisfaction = new Satisfaction();
        SatisfactionServices srvSat = new SatisfactionServices();
        CommandeServices srvCom = new CommandeServices();
        if (!buttonPas && !buttonPeu && !buttonSat && !buttonTre) {
            JOptionPane jop = new JOptionPane();
            jop.showMessageDialog(this, "Vous n'avez pas sélectionné la satisfaction");
        } else {
            if (buttonPas) {
                satisfaction.setTauxSatisfaction(TauxSatisfaction.PASSATISFAIT);
            } else if (buttonPeu) {
                satisfaction.setTauxSatisfaction(TauxSatisfaction.PEUSATISFAIT);
            } else if (buttonSat) {
                satisfaction.setTauxSatisfaction(TauxSatisfaction.SATISFAIT);
            } else if (buttonTre) {
                satisfaction.setTauxSatisfaction(TauxSatisfaction.TRESSATISFAIT);
            }
            satisfaction.setDate(new DateTime().toDate());
            srvSat.create(satisfaction, this.commande);
        }
        ficheClient.majCommandes();
        welcome.setListSatisfaction();
        this.dispose();
    }//GEN-LAST:event_jButtonValiderActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupSatisfaction;
    private javax.swing.JButton jButtonValider;
    private javax.swing.JLabel jLabelTitre;
    private javax.swing.JLabel jLabelTitre1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRadioButtonPaSatisfait;
    private javax.swing.JRadioButton jRadioButtonPeSatisfait;
    private javax.swing.JRadioButton jRadioButtonSatisfait;
    private javax.swing.JRadioButton jRadioButtonTSatisfait;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
